package com.yc.eduservice.mapper;

import com.yc.eduservice.model.entities.UserCourseEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserCourseMapper {
    //    学生添加选课
    @Insert("insert into user_courses values (null,#{course_id},#{course_name},#{course_code},#{student_user_id},#{teacher_user_id},#{student_realname},#{teacher_realname},#{user_score});")
    int addUserCourse(UserCourseEntity userCourseEntity);

    //    查看选择课程的学生列表
    @Select("SELECT * FROM user_courses WHERE course_id = #{course_id}")
    public List<UserCourseEntity> viewSelectedStudents(int course_id);
    //查看学生选择的课程列表
    @Select("SELECT * FROM user_courses WHERE student_user_id = #{studentId}")
    public List<UserCourseEntity> selectedCoursesOfStudentId(int studentId);
    /*user_courses*/
    @Update("UPDATE user_courses SET user_score=#{user_score} WHERE course_id=#{course_id} AND student_user_id=#{student_user_id}")
    public int checkScore(@Param("course_id") int courseId, @Param("student_user_id") int studentId, @Param("user_score") int userScore);

    @Select("SELECT * FROM user_courses WHERE course_id=#{course_id} AND student_user_id=#{student_user_id}")
    public UserCourseEntity selectByCourseAndStudentId(@Param("course_id") int courseId, @Param("student_user_id") int studentId);

    @Select("SELECT course_name ,user_score FROM user_courses WHERE  student_user_id= #{studentId}")
    public List<UserCourseEntity> myScore(int studentId);

    //    取消选课
    @Delete("DELETE FROM user_courses WHERE course_id = #{course_id} AND student_user_id = #{student_user_id};")
    public int deleteStudentCourse(@Param("course_id") int courseId, @Param("student_user_id") int studentId);

}
